Learning binary crap for real

Here's a good intro lesson


In [3]:
0b0 + 0b1000


Out[3]:
8

In [8]:
0b101


Out[8]:
5

In [11]:
5 << 1 # should multiply by 2 aka 10


Out[11]:
10

In [12]:
10 >> 1 # should devide by 2 aka 5


Out[12]:
5

In [23]:
~5 # ~ means bitwise not


Out[23]:
-6

In [32]:
5 & 4 # & means bitwise and


Out[32]:
4

In [33]:
5 | 4 # | means or


Out[33]:
5

In [31]:
5 ^ 4 # ^ means xor aka exlusive or


Out[31]:
1

In [35]:
5 ^ 1 # property of xor.... if you xor something with the output of that item and it's previous exor valy you get the original value


Out[35]:
4

In [ ]: